#页面类
    # A3mall 搜索
import time

from unit_729.Base.Base import Base
from selenium.webdriver.common.by import By
class Page2(Base):
    #点击登录
    login_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def login(self):
        self.click(self.login_loc)
    # 登录文本
    d_loc = (By.CLASS_NAME,'reg-new')
    def d(self):
        return self.text(self.d_loc)
    # 输入用户名
    username_loc = (By.NAME,'username')
    def username(self):
        self.send_keys(self.username_loc,'15821860061')
    # 输入密码
    password_loc = (By.NAME,'password')
    def password(self):
        self.send_keys(self.password_loc,'12345678')
    # 点击登录按钮
    finish_btn_loc = (By.XPATH,'//*[@id="theForm"]/div[5]/a')
    def finish_btn(self):
        self.click(self.finish_btn_loc)
    # 断言欢迎回来
    duanyuan_loc = (By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]')
    def duanyan(self):
        return self.text(self.duanyuan_loc)

    # 首页
    shouye_loc = (By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def shouye(self):
        self.click(self.shouye_loc)
    # 1.定位器
    keywords_loc = (By.XPATH, '/html/body/div[2]/div/div/form/div[1]/input')
    # keywords_loc = (By.NAME,'keywords')
    # 2.页面元素的封装
    def keywords(self):
        self.send_keys(self.keywords_loc,'手机')
    # 点击搜索
    search_btn_loc = (By.XPATH,'//*[@id="searchForm"]/div[2]/input')


    def search_btn(self):
        self.click(self.search_btn_loc)

    # 点击商品
    goods_loc = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[3]/div[1]/span/a/img')
    def goods(self):
        self.click(self.goods_loc)
    # 断言商品价格
    goods_price_loc = (By.XPATH,'/html/body/div[5]/div/div[2]/form/div/div[3]/div[1]/div[2]/span[2]')
    def goods_price(self):
        self.text(self.goods_price_loc)
    # 商品数量
    store_nums_loc = (By.ID,'store_nums')
    def store_nums(self):
        self.clear(self.store_nums_loc)
        time.sleep(2)
        self.send_keys(self.store_nums_loc,'2')
    #点击立即购买
    buy_cart_loc = (By.ID,'buy-cart')
    def buy_cart(self):
        self.click(self.buy_cart_loc)
    # 下一步
    xia_loc =(By.XPATH,'/html/body/div[4]/form/div[5]/div[2]/a[2]')
    def xia(self):
        self.click(self.xia_loc)
    # 3 业务逻辑调用
    def luoji_01_login(self):
        self.open_url('http://10.59.9.12:7001')
        self.login()
        d=self.d()
        print(d)
        assert '会员登录' in d
        time.sleep(1)
        self.username()
        self.password()
        time.sleep(10)
        self.finish_btn()
        print(self.duanyan())

        time.sleep(5)
        self.shouye()
        self.keywords()
        time.sleep(2)
        self.search_btn()
        self.goods()
        print(self.goods_price())
        self.store_nums()
        self.buy_cart()
        self.xia()
